config: drop double size lease times; they are all UINT32_MAX;
authorPaul Donald <[email protected]>
Fri, 3 Oct 2025 14:36:03 +0000 (16:36 +0200)
committerÁlvaro Fernández Rojas <[email protected]>
Mon, 13 Oct 2025 07:53:14 +0000 (09:53 +0200)
This now prevents implicit 64 bit->32 bit truncation which may flag
compiler errors later on down the road.

All of the variables receiving from parse_leasetime() are uint32_t
anyway, so max 136 years of valid lease time will have to suffice :)

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/225
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/config.c

index ae6675c5501b2bca8899371cfe7582b071da1d7a..7f112816aecabb982bee5133d5305d9b2451859b 100644 (file)
@@ -431,9 +431,9 @@ static void set_config(struct uci_section *s)
        }
 }
 
-static double parse_leasetime(struct blob_attr *c) {
+static uint32_t parse_leasetime(struct blob_attr *c) {
        char *val = blobmsg_get_string(c), *endptr = NULL;
-       double time = strcmp(val, "infinite") ? strtod(val, &endptr) : UINT32_MAX;
+       uint32_t time = strcmp(val, "infinite") ? (uint32_t)strtod(val, &endptr) : UINT32_MAX;
 
        if (time && endptr && endptr[0]) {
                switch(endptr[0]) {
@@ -452,7 +452,7 @@ static double parse_leasetime(struct blob_attr *c) {
        return time;
 
 err:
-       return -1;
+       return 0;
 }
 
 static void free_lease(struct lease *l)
@@ -585,8 +585,8 @@ int set_lease_from_blobmsg(struct blob_attr *ba)
        }
 
        if ((c = tb[LEASE_ATTR_LEASETIME])) {
-               double time = parse_leasetime(c);
-               if (time < 0)
+               uint32_t time = parse_leasetime(c);
+               if (time == 0)
                        goto err;
 
                l->leasetime = time;
@@ -1061,9 +1061,9 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                iface->no_dynamic_dhcp = !blobmsg_get_bool(c);
 
        if ((c = tb[IFACE_ATTR_LEASETIME])) {
-               double time = parse_leasetime(c);
+               uint32_t time = parse_leasetime(c);
 
-               if (time >= 0)
+               if (time > 0)
                        iface->dhcp_leasetime = time;
                else
                        syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
@@ -1072,25 +1072,25 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
        }
 
        if ((c = tb[IFACE_ATTR_MAX_PREFERRED_LIFETIME])) {
-               double time = parse_leasetime(c);
+               uint32_t time = parse_leasetime(c);
 
-               if (time >= 0) {
+               if (time > 0)
                        iface->max_preferred_lifetime = time;
-               } else {
+               else
                        syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
                               iface_attrs[IFACE_ATTR_MAX_PREFERRED_LIFETIME].name, iface->name);
-               }
+
        }
 
        if ((c = tb[IFACE_ATTR_MAX_VALID_LIFETIME])) {
-               double time = parse_leasetime(c);
+               uint32_t time = parse_leasetime(c);
 
-               if (time >= 0) {
+               if (time > 0)
                        iface->max_valid_lifetime = time;
-               } else {
+               else
                        syslog(LOG_ERR, "Invalid %s value configured for interface '%s'",
                               iface_attrs[IFACE_ATTR_MAX_VALID_LIFETIME].name, iface->name);
-               }
+
        }
 
        if ((c = tb[IFACE_ATTR_START])) {